//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//#include "windows.h"
 
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
String ShowDoub2(double x) //ʾλС
{
  x = x + 0.005;
  long y = x*100;
  x = y/100.0;
  return FloatToStr(x);
}
String TForm1::GetDrivType(UINT DrivType)
{
  String DrivTypeStr;
  if(DrivType == DRIVE_FIXED)
         {
            DrivTypeStr = "ش";
         }

         else if(DrivType == DRIVE_CDROM)
         {
            DrivTypeStr =  "";
         }
         else if(DrivType == DRIVE_REMOVABLE)
         {
            DrivTypeStr = "ƶ";
         }
         else if(DrivType == DRIVE_REMOTE)
         {
            DrivTypeStr = "";
         }
         else if(DrivType == DRIVE_RAMDISK)
         {
            DrivTypeStr = "RAM";
         }
         else if (DrivType == DRIVE_UNKNOWN)
         {
           DrivTypeStr = "δ֪豸";
         }
         else if (DrivType == 1)
         {
           DrivTypeStr = "Ŀ¼";
         }
  return DrivTypeStr;
}




void __fastcall TForm1::ListBox1Click(TObject *Sender)
{

  UINT DrivType;
  unsigned long lpSectorsPerCluster;
 unsigned long lpBytesPerSector;
 unsigned long lpNumberOfFreeClusters;
 unsigned long lpTotalNumberOfClusters;
 char FileName[100],tmpDrivCh;
 String DrivStr;
 for(int i=0;i<ListBox1->Items->Count;i++)
 {
   if(ListBox1->Selected[i])
   {
     DrivStr = ListBox1->Items->Strings[i].SubString(0,1);
     break;
   }

 }
  char RootDirtmp[4]={'x',':','\\','\0'},*pCh;//????????????????   "C:\\"
  pCh = DrivStr.c_str();
  RootDirtmp[0] = pCh[0];

  GroupBox1->Caption = "  " + (String)RootDirtmp[0] + "  йϢ";

  DrivType = GetDriveType(RootDirtmp);

  Label1->Caption = "ͣ           " + GetDrivType(DrivType);

  DWORD SeriaNumber = NULL;

  GetVolumeInformation(RootDirtmp,NULL,NULL,&SeriaNumber,NULL,NULL,FileName,100);

  Label2->Caption = "ļϵͳ    " + (String)FileName;


  GetDiskFreeSpace(RootDirtmp,&lpSectorsPerCluster,&lpBytesPerSector,&lpNumberOfFreeClusters,&lpTotalNumberOfClusters);
  double  FreeSpace = (double)lpBytesPerSector * lpSectorsPerCluster * lpNumberOfFreeClusters;
  double  TotalSpace = (double)lpBytesPerSector * lpSectorsPerCluster * lpTotalNumberOfClusters;

   Label3->Caption = "ÿռ䣺" + (String)(TotalSpace-FreeSpace) + "  ֽ";
   Label4->Caption = "ÿռ䣺" + (String)FreeSpace + "    ֽ";
   Label5->Caption = "    䣺" + (String)TotalSpace + "  ֽ";
  
   Label6->Caption =  ShowDoub2((TotalSpace-FreeSpace)/1024/1024/1024) + "	GB";
   Label7->Caption =  ShowDoub2(FreeSpace/1024/1024/1024)+ "	GB";
   Label8->Caption =  ShowDoub2(TotalSpace/1024/1024/1024)+ "	GB";

   Label9->Caption =  "кţ  " + (String)SeriaNumber;


}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
 int DiskNum = 0,DrivNameLength;   
  DWORD DiskInfo;
  DiskInfo = GetLogicalDrives();
  String str="";
  while(DiskInfo)//ͨѭDiskInfoÿһλǷΪ1ӦǷ
  {
     if(DiskInfo&1)
     {
       DiskNum++;
     }
     DiskInfo = DiskInfo >> 1;//ƶһλ
  }
  DrivNameLength = GetLogicalDriveStrings(0,NULL); // ȡַϢ
  char* DrivNameStr = new char[DrivNameLength];
  GetLogicalDriveStrings(DrivNameLength,(LPTSTR)DrivNameStr);
  ListBox1->Items->Clear();
  for(int i=0;i<DrivNameLength/4;++i) //λȡÿϢ
  {
     char RootDir[3]={DrivNameStr[i*4],':','\\'};
     str = RootDir[0];
     str = str + " ";
     ListBox1->Items->Add(str);
  }


}
//---------------------------------------------------------------------------
